#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1000
#define LEN 2

int **result;
int *path;
int resultTop;
int pathTop;
int *arr;
int arrCount;
int minIndexSum = MAX;
int bestIndex = -1;

void backtracking(int tar, int startIndex) {
    if (pathTop == LEN) {
        int curSum = 0;
        int curIndexSum = 0;
        for(int i = 0; i < LEN; i++) {
            curSum += arr[path[i]];
            curIndexSum += path[i];
        }
        if (curSum == tar) {
            int *tmp = (int *)malloc(sizeof(int) * LEN);
            for(int i = 0; i < LEN; i++) {
                tmp[i] = arr[path[i]];
            }
            if (curIndexSum < minIndexSum) {
                bestIndex = resultTop;
                minIndexSum = curIndexSum;
            }
            result[resultTop++] = tmp;
        }
        return;
    }
    // note 1# 容易写成 int i = 0
    for(int i = startIndex; i < arrCount; i++) {
        path[pathTop++] = i;
        backtracking(tar, i + 1);
        pathTop--;
    }
}

int main() {
    result = (int **)malloc(sizeof(int *) * MAX);
    for(int i = 0; i < MAX; i++) {
        result[i] = (int *)malloc(sizeof(int) * LEN);
    }
    path = (int *)malloc(sizeof(int) * LEN);
    arr = (int *)malloc(sizeof(int) * MAX);
    arrCount = 0;

    char *input = (char *)malloc(sizeof(char) * MAX);
    fgets(input, sizeof(char) * MAX, stdin);
    input[strcspn(input, "\n")] = 0;
    char *buf = strtok(input, ",[]");
    while(buf != NULL) {
        arr[arrCount++] = atoi(buf);
        buf = strtok(NULL, ",[]");
    }

    int target;
    scanf("%d", &target);
    pathTop = resultTop = 0;

    backtracking(target, 0);

    printf("[%d", result[bestIndex][0]);
    for(int i = 1; i < LEN; i++){
        printf(", %d", result[bestIndex][i]);
    }
    printf("]\n");

    
}